<template>
  <div class="count">
    <h2>当前求和为：{{ sum }}</h2>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="add">+</button>
    <button @click="minus">-</button>
    <button @click="OddAdd">当前和为奇数再+</button>
    <button @click="waitAdd">等一等再+</button>
  </div>
</template>

<script>
  export default {
    name:'Count',
    data() {
      return {
        sum:0, //当前的和
        n:1 //用户选择的数字
      }
    },
    methods: {
      add(){
        this.sum += this.n
      },
      minus(){
        this.sum -= this.n
      },
      OddAdd(){
        if(this.sum % 2){
          this.sum += this.n
        }
      },
      waitAdd(){
        setTimeout(() => {
          this.sum += this.n
        },1000);
      },
    },
  }
</script>

<style>
  .count {
    background-color: skyblue;
    border-radius: 10px;
    box-shadow: 0 0 10px;
    padding: 10px;
  }
  button {
    margin: 0 5px;
  }
  button,select {
    height: 25px;
  }
</style>